package com.example.satoken.config;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

/**
 * @author chenhh
 * @version v1.0
 * @date 2025/5/12 16:37
 */
@Data
@Accessors(chain = true)
public class Result {
    private int code;
    private String msg;
    private Object data;

    public static Result ok(String msg) {
        return new Result().setCode(200).setMsg(msg);
    }
    public static Result ok(int code,String msg) {
        return new Result().setCode(code).setMsg(msg);
    }

    public static Result error(String msg) {
        return new Result().setCode(500).setMsg(msg);
    }
    public static Result error(int code,String msg) {
        return new Result().setCode(code).setMsg(msg);
    }

    public Result put(String key, Object value) {
        if (data == null)
        {
            data = new HashMap<>();
        }
        ((Map) data).put(key, value);
        return this;
    }
}
